﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCS.UI.Utils;

//对应ServiceZMCS02.java
namespace Baosight.ZNH.ZMCS.UI
{
    /// <summary>
    /// 系统模块  明细页面  
    /// </summary>
    /// Title:ZMCS03
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 张志芳
    /// Version: 1.0
    /// History:
    ///       2010-12-14  张志芳   [创建]
    ///
    public partial class ZMCS03 : EFViewCmes
    {
        private SystemModuleBlock block = new SystemModuleBlock();//构造前台下拉列表

        public ZMCS03()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }
        /// <summary>
        /// Load事件中初始化父类EFViewCmesProperty的值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            _view.ListPageNo = "ZMCS03";
            _view.ViewType = "tree";

            _view.Args.Add("initArgs", this.fdKeyId.GetDataValue().ToString());
            _view.Args.Add("fdParentId", this.fdKeyId.GetDataValue().ToString());
            _view.Args.Add("fdParentName", this.fdParentName.GetDataValue().ToString());
            _view.Args.Add("isLeaf", this.isLeaf.GetDataValue().ToString());

            base.ViewProperty = _view;
        }

        /// <summary>
        /// 重新初始化方法
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(EIInfo initData)
        {
            initData.AddBlock(block.GetStatus(false));//模块状态 再用|停用
            initData.AddBlock(block.GetNatureBlock());//模块性质 标准版|扩展版
            initData.AddBlock(block.GetTypeBlock());//模块类型 业务|公共|基础|报表|统计

            base.Initialize(initData);
            //判断页面时新增页还是编辑页
            InitDataSet(initData);
        }

        /// <summary>
        /// 给Mode付值
        /// </summary>
        /// <param name="initData"></param>
        private void InitDataSet(EIInfo initData)
        {
            base.Mode = (OperationMode)Enum.Parse(typeof(OperationMode), "Update", true);
            this.fdModuleNo.IsReadOnly = true;
            this.fdModuleName.IsReadOnly = true;
        }

        public override void OnUpdateButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnSureButtonClick(sender, e);
        }

        #region 公用方法
        /// <summary>
        /// 根据 moduleLevel的值，返回fdModuleLevelName的值
        /// </summary>
        /// <param name="moduleLevel"></param>
        /// <returns></returns>
        public void SetModuleLevelName(string moduleLevel)
        {
            if (null == moduleLevel)
            {
                this.fdModuleLevelName.Value = "系统模块";
            }
            switch (moduleLevel)
            {
                case "0":
                    this.fdModuleLevelName.Value = "系统模块";
                    break;
                case "1":
                    this.fdModuleLevelName.Value = "一级模块";
                    break;
                case "2":
                    this.fdModuleLevelName.Value = "二级模块";
                    break;
                case "3":
                    this.fdModuleLevelName.Value = "三级模块";
                    break;
                default:
                    this.fdModuleLevelName.Value = "系统模块";
                    break;
            }
        }

        /// <summary>
        /// 重写基类方法：根据数据的改变更新主页面的数据
        /// </summary>
        /// <param name="data"></param>
        public override void UpdateHomePageData(EIInfo data)
        {
            // 数据发布
            IEventAggregator eventAggreator = Container.Resolve<IEventAggregator>();
            EIDataPublishedEvent dataPublishedEvent = eventAggreator.GetEvent<EIDataPublishedEvent>();
            dataPublishedEvent.Publish(data);
        }

        /// <summary>
        /// 模块级别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdModuleLevelName_Loaded(object sender, RoutedEventArgs e)
        {
            this.SetModuleLevelName(this.fdModuleLevel.Value.ToString());//模块级别名称
        }

        #endregion

    }
}
